<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>
      明白了！你希望输出的是一个滑动窗口效果，每次取两个连续的元素。下面是实现这种效果的几种方式。
    </title>
    <script src="../helpers/bing.js"></script>
  </head>
  <body>
    <script>
      const arr = ["a", "b", "c", "d", "e"];
      let previousElement = null; // 用于保存前一个元素

      for (const [index, element] of arr.entries()) {
        if (index === 0) {
          console.log("prev: null");
          console.log(element);
          console.log("--------------------");
        } else {
          console.log("prev: ", previousElement);
          console.log(element);
          console.log("--------------------");
        }

        // 更新previousElement为当前元素
        previousElement = element;
      }
    </script>
  </body>
</html>
